package com.springcloudalibaba.apiPay.controller;

import com.alipay.api.AlipayApiException;
import com.springcloudalibaba.apiPay.service.impl.AlibabaPayCallbackServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;


import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @描述: 阿里巴巴支付回调
 * @作者: lixing
 * @日期 2021/7/8 15:29
 */
@Controller
@RequestMapping(("alibabaPayCallback"))
public class AlibabaPayCallbackController {
    @Autowired
    private AlibabaPayCallbackServiceImpl alibabaPayCallbackService;

    /**
     * @描述 支付成功后，点击页面的完成按钮回调
     * @作者 lixing
     * @日期 2021/7/8 15:40
     * @Param [request, response]
     */
    @GetMapping("returnUrl")
    public ModelAndView returnUrl(HttpServletRequest request, HttpServletResponse response) {
        return alibabaPayCallbackService.returnUrl(request, response);
    }
    /**
     * @描述 支付成功异步回调
     * @作者 lixing
     * @日期 2021/7/8 15:40
     * @Param [request, response]
     */
    @PostMapping("notifyUrl")
    public void notifyUrl(HttpServletRequest request, HttpServletResponse response) throws IOException, AlipayApiException {
        alibabaPayCallbackService.notifyUrl(request, response);
    }

}
